package com.oazon.moco.link.serialport;

import java.util.Arrays;

import com.oazon.moco.link.core.LinkEvent;
import com.oazon.moco.link.core.LinkEventController;
import com.oazon.moco.link.core.LinkEventListener;
import com.oazon.moco.link.core.LinkSDK;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.BatteryEvent;
import com.oazon.moco.link.event.BatteryStatus;
import com.oazon.moco.serialport.SerialSend;

public class SerialBatteryEventListener extends LinkEventListener {

	public SerialBatteryEventListener(LinkEventSource... sources) {
		setBlackList(Arrays.asList(sources));
	}

	@Override
	public void onLinkEvent(LinkEvent event) {
		if(filter((LinkEventSource)event.getSource()) || !(event instanceof BatteryEvent)){
			return;
		}
		BatteryEvent e = (BatteryEvent)event;
		e.getCharge_percent();
		
		if(e.getCharge_percent()==100){
			//发磅dc
			//发送charget
			SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_EXTERNAL);
			SerialSend.getInstance().sendStatus(SerialSend.Serial_POWER_CHARGE);
		}
		
		if(e.getCharge_percent()<=3){
			LinkSDK.getInstance().setLow(LinkEventController.serialSource);
		}
		
		
		System.out.println("battery status is changed to "+e.getState());
	}	
}
